package com.zzyy.study.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.openai.OpenAiAudioTranscriptionClient;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther zzyy
 * @create 2024-05-18 17:37
 */
@RestController
public class Audio2TextOpenAIController
{
    @Resource
    private OpenAiAudioTranscriptionClient openAiAudioTranscriptionClient;

    //http://localhost:24512/ai/audio?language=en
    @GetMapping(value = "/ai/audio")
    public Object audioToText(@RequestParam(value = "language",defaultValue = "en") String language)
    {
        //org.springframework.core.io.Resource audioFile  = new ClassPathResource("abc.mp4");
        ClassPathResource audioFile = null;

        if(language.equalsIgnoreCase("zh")) {
            audioFile  = new ClassPathResource("三国英杰.mp4");
        }else {
            audioFile  = new ClassPathResource("listen.mp3");
        }

        String retValue = openAiAudioTranscriptionClient.call(audioFile);
        System.out.println(retValue);


        return retValue;
    }
}